home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Round matrix elements.
-
- // Syntax: C = chop ( X , t )
-
- // Description:
-
- // C is the matrix obtained by rounding the elements of X to t
- // significant binary places. Default is t = 24, corresponding to
- // IEEE single precision.
-
- // This file is a translation of chop.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- //-------------------------------------------------------------------//
-
- chop = function ( x , t )
- {
- local (x, t)
-
- if (!exist(t)) { t = 24; }
- m = x.nr; n = x.nc;
-
- // Use the representation:
- // x[i;j] = 2^e[i;j] * .d[1]d[2]...d[s] * sign(x[i;j])
-
- // On the next line `+(x==0)' avoids passing a zero argument to LOG, which
- // would cause a warning message to be generated.
-
- y = abs(x) + (x==0);
- e = floor(log(y)./log(2) + 1);
- p = (2.*ones(m,n)).^(t-e);
- c = round(p.*x)./p;
-
- return c;
- };
-